import type { LanguageType } from '@lingshu/language-lib';
import { getBatchLangModuleData } from '@lingshu/language-lib';
import zhCh from 'element-plus-cisdi/es/locale/lang/zh-cn.mjs';
import { ref } from 'vue';
import { waringTip } from '@/utils/WaringTips.ts';
import { proxyLanguageRequest } from './TransformRequest.ts';

const locales = ref({} as any);
const ELEMENT_PLUS_CISDI_LANG_MODULE = 'element_plus_cisdi';

// eslint-disable-next-line unused-imports/no-unused-vars
export async function changeElementPlusLang(config: {
  lang: LanguageType
  langJson?: Record<string, any>
}) {
  let elLangJson: any = zhCh;

  try {
    const data = await getBatchLangModuleData([{
      moduleCode: ELEMENT_PLUS_CISDI_LANG_MODULE,
      langJson: zhCh,
    }], proxyLanguageRequest);
    elLangJson = data.langMap[ELEMENT_PLUS_CISDI_LANG_MODULE] || {};
  } catch (error) {
    waringTip(error);
    console.error(error);
  }

  locales.value = elLangJson;

  return Promise.resolve(true);
}

export function getElementPlusLocales() {
  return locales;
}
